var mongoose = require('mongoose')
var Schema = mongoose.Schema

var PostingSchema = new Schema({
    id: {
        type: Number,
        required: true
    },
    username: {
        type: String,
        required: true
    },
    useravatar: {
        type: String,
        required: true
    },
    introduce: {
        type: String,
        required: true
    },
    title: {
        type: String,
        required: true
    },
    briefInfo: {
        type: String,
        required: true
    },
    content: {
        type: String,
        required: true
    },
    tagArray: [String],
    create_time: {
        type: Date,
        default: Date.now()
    },
    like: {
        type: Number,
        default: 0
    },
    collections: {
        type: Number,
        default: 0
    },
    comments: [{
        id: {
            type: Number,
            default: 1
        },
        username: {
            type: String,
            default: ''
        },
        content: {
            type: String,
            default: ''
        },
        isOriginalPoster: {
            type: Boolean,
            default: false
        },
        like: {
            type: Number,
            default: 0
        },
        children: [{
            id: {
                type: Number,
                default: 2
            },
            isOriginalPoster: {
                type: Boolean,
                default: false
            },
            replyUsername: {
                type: String,
                default: ''
            },
            showReplyText: {
                type: Boolean,
                default: false
            },
            username: {
                type: String,
                default: ''
            },
            content: {
                type: String,
                default: ''
            }
        }]
    }]
})

module.exports = mongoose.model('Posting', PostingSchema)